<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改kettle运行提醒信息')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-warnmsg-edit" th:object="${ktWarnMsg}">
            <input name="id" th:field="*{id}" type="hidden">
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">通知类型：</label>
                <div class="col-sm-8">
                    <label class="radio-box"> <input type="radio" name="contactType" value="1" th:checked="*{'1' == contactType}" disabled/> 短信 </label>
                    <label class="radio-box"> <input type="radio" name="contactType" value="2" th:checked="*{'2' == contactType}" disabled/> e-mail </label>
                    <label class="radio-box"> <input type="radio" name="contactType" value="3" th:checked="*{'3' == contactType}" disabled/> 钉钉 </label>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">电话号码：</label>
                <div class="col-sm-8">
                    <input name="phoneNum" th:field="*{phoneNum}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">e_mail地址：</label>
                <div class="col-sm-8">
                    <input name="eMailAddr" th:field="*{eMailAddr}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">钉钉Webhook地址：</label>
                <div class="col-sm-8">
                    <input name="dingWebHook" th:field="*{dingWebHook}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">状态：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('sys_normal_disable')}">
                        <input type="radio" th:id="${dict.dictCode}" name="status" th:value="${dict.dictValue}" th:field="*{status}">
                        <label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var contactType = [[${ktWarnMsg.contactType}]];

        if (contactType === '1') {
            $("#eMailAddr").parents(".form-group").hide();
            $("#dingWebHook").parents(".form-group").hide();
        } else if (contactType === '2') {
            $("#phoneNum").parents(".form-group").hide();
            $("#dingWebHook").parents(".form-group").hide();
        } else {
            $("#phoneNum").parents(".form-group").hide();
            $("#eMailAddr").parents(".form-group").hide();
        }

        var prefix = ctx + "busi/warnmsg";
        $("#form-warnmsg-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-warnmsg-edit').serialize());
            }
        }

        $(function () {
            $('input').on('ifChecked', function(event){
                var localName=event.target.name;
                if (localName === 'status') {
                    return;
                }
                var authType = $(event.target).val();
                if (authType === "1") {
                    $("#eMailAddr").parents(".form-group").hide();
                    $("#dingWebHook").parents(".form-group").hide();
                    $("#phoneNum").parents(".form-group").show();
                } else if (authType=== "2") {
                    $("#phoneNum").parents(".form-group").hide();
                    $("#dingWebHook").parents(".form-group").hide();
                    $("#eMailAddr").parents(".form-group").show();
                } else {
                    $("#phoneNum").parents(".form-group").hide();
                    $("#dingWebHook").parents(".form-group").show();
                    $("#eMailAddr").parents(".form-group").hide();
                }
            });
        });
    </script>
</body>
</html>